﻿using KinonekoSoftware.CodariaDB.Documents.DataParts.Modules.RVE;
using KinonekoSoftware.Studio.Models.Modules.RVE;
using Microsoft.Xaml.Behaviors;
using System.Windows;
using KinonekoSoftware.Foundation.UI;
using KinonekoSoftware.Foundation.UI.Controls;

namespace KinonekoSoftware.Studio.Resources.Behaviors
{
    public class FindZodiacIconBehavior : Behavior<Iconify>
    {
        protected override void OnAttached()
        {
            if (AssociatedObject.DataContext is RVEZodiacPresenter zodiac)
            {
                zodiac.ValueChanged += OnValueChanged;
            }

            base.OnAttached();
        }

        void OnValueChanged(Zodiac value)
        {
            AssociatedObject.Icon = AssociatedObject.FindResource(value.ToString()) as Geometry;
            Xplat.Debug($"正在查找资源：{value.ToString()}，结果为:{AssociatedObject.Icon is not null}");
        }

        protected override void OnDetaching()
        {

            if (AssociatedObject.DataContext is RVEZodiacPresenter zodiac)
            {
                zodiac.ValueChanged -= OnValueChanged;
            }
            
            base.OnDetaching();
        }
    }
}